﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using RoadTeam.Model;
using RoadTeam.Enums;
using RoadTeam.SysInterface;
using RoadTeam.Pub;


namespace RoadTeam.BLL
{
    public class CsMaintenanceFileBll
    {

        private static object o = new object();

        public DataTable GetEmpty()
        {
            SqlWhere where = new SqlWhere();
            where.SelectColumn = @" Top 0 BusninessIdentitfier,BusninessType,ImgType,ImgName,StaffName";
            return CsMaintenanceFile.Select(where, GlobalConfig.ConnectionString);
        }

        public bool InsertFileInfo(String BusninessIdentifier, String FilePath, String RtFilePath, String FileName, string FileType, String BusninessType)
        {    
            DataTable dt= FactoryClass.CreateCsMaintenanceFile().GetEmptyData();
            CsMaintenanceFile fileInfos = new CsMaintenanceFile();
            lock (o)
            {
               //BusninessID,BusninessType,ImgType,ImgName,StaffName,ImagePath,App_Identifier
               DataRow dr = dt.NewRow();
                String  Identifier= CreateIdentifier.GetIdentifier();
                dr[6] = Identifier;
               dr[5] = RtFilePath + "/"; ;
               dr[0] = FactoryClass.CreateCsMaintenance().GetSingleMaintenanceByIdentities(BusninessIdentifier);
               dr[1] = BusninessType;
               dr[2] = FileType;
               dr[3] = FileName;
               dr[4] = DBNull.Value;
               dt.Rows.Add(dr);

               fileInfos.CsMaintenanceFileIdentitfier = Identifier;
               fileInfos.BusninessIdentitfier = BusninessIdentifier;
               fileInfos.BusninessType = BusninessType;
               fileInfos.ImgName = FileName;
               fileInfos.ImgType = FileType;
               fileInfos.ImagePath = FilePath;
               fileInfos.StaffName = DBNull.Value.ToString();
            }
            bool flag = false;

            flag =( FactoryClass.CreateCsMaintenanceFile().InSertFileInfo(dt)
            && CsMaintenanceFile.InserObjedct(fileInfos, new List<string>(), GlobalConfig.ConnectionString));

            return flag;
        }

    }
}
